package auctionhaus

import grails.converters.JSON
import grails.plugin.jms.JmsService

/**
 * Created by IntelliJ IDEA.
 * User: lemmej1
 * Date: 4/12/12
 * Time: 7:51 PM
 * To change this template use File | Settings | File Templates.
 */
class MessagingIntegrationTests extends GroovyTestCase {
    def jmsService

    def testMessageSentToQueue() {

        def bob = new Customer(emailAddress: 'bob@umn.edu', password: 'password')
        bob.bids = new HashSet<Bid>()
        bob.listings = new HashSet<Listing>()

        def alice = new Customer(emailAddress: 'alice@umn.edu', password: 'password')
        alice.bids = new HashSet<Bid>()
        alice.listings = new HashSet<Listing>()

        def customerService = new CustomerService()
        assert customerService.createCustomer(alice) == alice
        assert customerService.createCustomer(bob) == bob

        def listing = new Listing(name: 'volleyball', endDateTime: new Date() + 5, seller: alice, startingBidAmount: 20)
        listing.bids = new HashSet<Bid>()
        def listingService = new ListingService()
        listingService.jmsService = this.jmsService
        assert listingService.createListing(listing) == listing

        def bid = new Bid(bidder: alice, listing: listing , amount: 25)
        assert listingService.placeBid(bid).bid == bid
        listing.addToBids(bid)

        listingService.closeListing(listing) == "closedListing"

        List messages = jmsService.browse(service: "notification", "standard", null)
        assert messages.size() == 0
    }
}
